import os

import pytest
from errors import Duplicate, Missing

os.environ["CRYPTID_UNIT_TEST"] = "true"
from model.user import User
from service import user


@pytest.fixture
def sample() -> User:
    return User(name="sjdfhsjkdahfjdsh", hash="aklsdjflaksfdj")


def test_create(sample):
    assert user.create(sample) == sample


def test_create_duplicate(sample):
    with pytest.raises(Duplicate):
        user.create(sample)


def test_get_one(sample):
    assert user.get_one(sample.name) == sample


def test_get_one_missing():
    with pytest.raises(Missing):
        user.get_one("hazadus")
